const api = require('./utils/api')

require('./common').then(cga => {
    const player = cga.GetPlayerInfo()

    const bag_goods_list = cga.getInventoryItems()
    const bag_pet_list = cga.GetPetsInfo();
    const bag_data = {
        name: player.name,
        goods_list: bag_goods_list,
        pet_list: bag_pet_list,
    }

    const 去银行 = () => {
        return leo.todo().then(() => {
            return leo.goto(n => n.falan.bank)
        }).then(() => {
            return leo.turnDir(0)
        }).catch(() => {
            return leo.next()
        })
    }

    去银行()
    const bank_goods_list = cga.GetBankItemsInfo();
    const bank_pet_list = cga.GetBankPetsInfo();
	const bank_money = cga.GetBankGold();
    const bank_data = {
        name: player.name,
        money: bank_money,
        goods_list: bank_goods_list,
        pet_list: bank_pet_list,
    }
    const sync = async () => {
        await api.syncUser(player)
        await api.syncUserBag(bag_data)
        await api.syncUserBank(bank_data)
    }
    sync()
});